package user;

import configuration.RobConfiguration;
import enumeration.EnumUserType;
import user.impl.BetterUser;
import user.impl.OOUser;

import java.util.ArrayList;
import java.util.HashMap;

public class UserManager {
    public static HashMap<String, IUser> userCache = new HashMap<>();
    public static ArrayList<IUser> allUserCache = new ArrayList<>();

    public static HashMap<String, IUser> getUserCache() {
        return userCache;
    }

    public static void setUserCache(HashMap<String, IUser> userCache) {
        UserManager.userCache = userCache;
    }

    public static void addUserCache(String customName,IUser user) {
        if(checkUsernameLength(user)){
            getUserCache().put(customName,user);
        }
    }

    public static void addUserCache(IUser user) {
        if(checkUsernameLength(user)){
            getUserCache().put(RobConfiguration.ROB_LOGIN_MODE.name()+"_"+user.getUsername(),user);
        }
    }

    public static ArrayList<IUser> getAllUserCache() {
        return allUserCache;
    }

    public static void setAllUserCache(ArrayList<IUser> allUserCache) {
        UserManager.allUserCache = allUserCache;
    }

    public static void addAllUserCache(IUser user) {
        if(checkUsernameLength(user)){
            getAllUserCache().add(user);
        }

    }

    public static boolean checkUsernameLength(IUser user){
//        robClass.logger.info("USERNAME_MAX_LENGTH:" + RobConfiguration.USERNAME_MAX_LENGTH);
//        robClass.logger.info("user.getUsername().length():" + user.getUsername().length());
        return user.getUsername().length()==RobConfiguration.USERNAME_MAX_LENGTH;
    }
}
